package com.cat.twoPointerTechnique;

import java.util.Arrays;
import java.util.HashMap;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/get-the-maximum-score/
 * @create 2025/8/6 19:37
 * @since JDK17
 */

public class Solution17 {
    static int MOD = ((int) (1e9 + 7));
    public int maxSum(int[] nums1, int[] nums2) {
        long ans = 0, sum1 = 0, sum2 = 0;
        int n = nums1.length, m = nums2.length, i, j;
        for (i = j = 0; i < n && j < m; ) {
            if (nums1[i] == nums2[j]) { // 遇到相同的了，可以求和了
                ans = (ans + nums1[i] + Math.max(sum1, sum2)) % MOD;
                sum1 = sum2 = 0;
                i++;
                j++;
            } else if (nums1[i] > nums2[j]) {   // 先让j先走
                sum2 += nums2[j++];
            } else {    // 先让i先走
                sum1 += nums1[i++];
            }
        }
        while (i < n) {
            sum1 += nums1[i++];
        }
        while (j < m) {
            sum2 += nums2[j++];
        }
        return ((int) ((ans + Math.max(sum1, sum2)) % MOD));
    }
}
